//--------------------------------------------------------------
//
// Qizhi Zhang 
// ezhung@gmail.com
// http://www.moorwind.com
//
//--------------------------------------------------------------
package reader.dao
{
	import flash.data.SQLConnection;
	import flash.filesystem.File;
	
	public class SqliteDAOFactory extends DAOFactory
	{
		//////////////////////////////////////////////////////////////////////////////
		//public properties
		
		public static const BD_NAME:String = "DataCache.db";
		
		public var connection:SQLConnection;
		
		//////////////////////////////////////////////////////////////////////////////
		//Constructor
		public function SqliteDAOFactory()
		{
			super();
			this.connection = creatConnection();
		}
		
		//////////////////////////////////////////////////////////////////////////////
		//methods
		
		public static function creatConnection():SQLConnection
		{
			var file:File = File.applicationDirectory.resolvePath(BD_NAME);
			if(file.exists)
			{
				var conn:SQLConnection = new SQLConnection();
				conn.open(file);
				return conn;
			}
			return null;
		}
		
		override public function get accountDAO():IAccountDAO
		{
			return new AccountDAO(connection);
		}
		
		override public function get labelDAO():ILabelDAO
		{
			return new LabelDAO(connection);
		}
		
		override public function get blogSourceDAO():IBlogSourceDAO
		{
			return new BlogSourceDAO(connection);
		}
		
		override public function get blogDAO():IBlogDAO
		{
			return new BlogDAO(connection);
		}
		
		override public function get draftDAO():IDraftDAO
		{
			return new DraftDAO(connection);
		}
		
		override public function get serviceDAO():IServiceDAO
		{
			return new ServiceDAO(connection);
		}
		
		override public function get mediaDAO():IMediaDAO
		{
			return new MediaDAO(connection);
		}
	}
}